home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12042 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  84 lines

  1. Path: news.oanet.com!usenet
  2. From: mape@freenet.edmonton.ab.ca
  3. Newsgroups: comp.lang.c++
  4. Subject: Help: student with passing by pointer to functions problem
  5. Date: Mon, 18 Mar 1996 00:27:45 GMT
  6. Organization: Central News Services
  7. Message-ID: <4ii6s7$s2a@hermes.oanet.com>
  8. NNTP-Posting-Host: dialin11.oanet.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hi All,
  12.  
  13.     I'm a student at NAIT.ab.ca, and am taking an introduction to Windows
  14. programming course.  I really enjoy his C++ language, but our text
  15. book has absolutly nothing on functions and far * pointers.
  16. Unfortunatly I won't be seeing the teacher before my Lab is due, so I
  17. thought I'd throw it out as a general question to the helpful
  18. individuals of this group.  
  19.     I am a little unclear as to how pass elements of a stucture form a
  20. dialog box function that is already using a far * pointer, to another
  21. function (a generic sort function).
  22.  
  23. Here is an example of what I'm trying to do:
  24.  
  25. struct GAMEDATA
  26. {
  27.     LOGFONT lfText;
  28.     COLORREF cTwoColor;
  29.     COLORREF cOneColor;
  30.     char aszName[5][5];
  31.     int iNumName;
  32. };
  33.  
  34. Is passed into the following dialogbox function:
  35. //prototype
  36. LRESULT CALLBACK fnAddPlayerProc( HWND, UINT, WPARAM, LPARAM );
  37.  
  38. and called from a menu item case, where the LPARAM is typecast to a
  39. struct far *:
  40. case IDM_PLAYERS_ADD:
  41. {
  42.     FARPROC lpfnDlg;
  43.     GAMEDATA far * ptrD;
  44.     ptrD = & stGData;
  45.     lpfnDlg = MakeProcInstance(( FARPROC ) fnAddPlayerProc,ghInst );
  46.     DialogBoxParam( ghInst, "AddPlayer", hWnd,( DLGPROC ) lpfnDlg, ( 
  47.                         LPARAM ) ptrD );
  48.     FreeProcInstance( lpfnDlg );                    
  49. break;
  50. }
  51.  
  52. In the function, it is typecast to a pointer to the struct in
  53. WM_INITDIALOG:
  54. LRESULT CALLBACK fnAddPlayerProc( HWND hDlg, UINT iMessage,
  55.                  WPARAM wParam, LPARAM lParam)
  56. {
  57.     static GAMEDATA far * localPtr;switch( iMessage )
  58.     switch( iMessage)
  59.         case WM_INITDIALOG:
  60.         {
  61.             localPtr = (GAMEDATA far * )lParam;
  62.             break;
  63.         }
  64.         case WM_COMMAND:
  65.         {
  66.  
  67.     Here, I would like to call a generic function to do a bubble sort
  68. using localPtr->aszName and localPtr->iNumName
  69. //prototype
  70. void fnSort( HWND, aszNAM[][5], iNumN );
  71. //call
  72.     fnSort(hDlg, localPtr->aszNames, localPtr->iNumName );
  73. //header
  74. void fnSort( HWND hDlg, char aszNAM[][5], int iNumN );
  75.  
  76. This dosen't work.
  77. Do I have to typecast the pointer in the function?
  78. Do I have to pass it the HWND?
  79.  
  80. Sincerely.
  81. Martin            martp@oanet.com
  82.             mape@freenet.edmonton.ab.ca
  83.  
  84.